package com.igeekhome.controller.api;

import com.igeekhome.pojo.DNetwork;
import com.igeekhome.pojo.DSpotDestination;
import com.igeekhome.pojo.SysStaff;
import com.igeekhome.service.IDestService;
import com.igeekhome.util.ResultBean;
import com.igeekhome.util.TableResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Romeo
 */
@RestController
@RequestMapping("/api/dest")
public class DestControllerApi {

    @Autowired
    private IDestService destService;

    @RequestMapping("/list")
    public TableResultBean list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit, Integer id, String name, HttpServletRequest request){
        DNetwork network = (DNetwork) request.getSession().getAttribute("network");
        Integer nid = network.getNetworkId();
        return destService.list(nid,name,id,page,limit);
    }
    @RequestMapping("/add")
    public ResultBean add(DSpotDestination dSpotDestination, HttpServletRequest request, String province, String city, String area, String address){
        SysStaff staff = (SysStaff)request.getSession().getAttribute("staff");
        DNetwork network = (DNetwork)request.getSession().getAttribute("network");
       return destService.add(dSpotDestination,staff.getStaffId(),network.getNetworkId(),province,city,area,address);
    }
    @RequestMapping("/edit")
    public ResultBean edit(DSpotDestination dSpotDestination, String province, String city, String area, String address){
        System.out.println("dSpotDestination========="+dSpotDestination);
        return destService.edit(dSpotDestination,province,city,area,address);
    }
    @RequestMapping("/delete")
    public ResultBean delete(String idsStr){
        return destService.delete(idsStr);
    }
}
